$(function(){
	//通过分类信息模糊查询app列表信息
	$("#backByLike").click(function(){
		//获取查条件信息
		var dataApp = $("#backAppInfoForm").serialize();
		
		$.ajax({
			type:"POST",
			data:dataApp,
			url:"getResponse",
			success:function(response){
				showBackApp(response.list);
				backPageStr(response);
			}
		})
		
		
	})
})



//显示页面无刷新
function showBackApp($param){
	var lists = $param;
	var htmlStr = "";
	console.info(lists);
	//清空tbody下的信息
	var tables = $("#backApp tbody").html("");
			if(lists.length>0){
				for(var i=0;i<lists.length;i++){
						if(lists[i].status==1){
							htmlStr = "<tr>"+
							"<td>"+lists[i].softwareName+"</td>"+
							"<td>"+lists[i].apkname+"</td>"+
							"<td>"+lists[i].softwareSize+"</td>"+
							"<td>"+lists[i].flatformName+"</td>"+
							"<td>"+lists[i].categoryLevel1Name+"--"+lists[i].categoryLevel2Name+"--"+lists[i].categoryLevel3Name+"</td>"+
							"<td>"+lists[i].statusName+"</td>"+
							"<td>"+lists[i].downloads+"</td>";
							if(lists[i].versionName==null){
								lists[i].versionName="";
							}
							htmlStr = htmlStr+"<td>"+lists[i].versionName+"</td>";
							var na = lists[i].status;
							htmlStr = htmlStr+"<td>"+
							"<button type='button' class='btn btn-default' data-toggle='tooltip'"+
						        "data-placement='top' title='查看并审核APP' onclick='backModal("+lists[i].id+")'>审核</button>"+
							"</td>"+
						"</tr>";
							tables.append(htmlStr);
						}
					
				}
			}

}

//页码
function backPages($page){
	//获取查询对象
	var selectObject =$("#backAppInfoForm").serialize();
	//获取当前页码
	var num =$page;
	//获取提交查询路径
	var url="getResponse";
	$.ajax({
		type:"POST",
		url:url,
		data:selectObject+"&num="+num,
		success:function(response){
			console.info("----"+response.list);
			showBackApp(response.list);
			backPageStr(response);
		},
		dataType:"JSON"
	})
}





//页码信息
function backPageStr($list){
	
	var info = $list;
	console.info(info);
	//
	//获取列表信息对象
	var strPage=	"<div class='col-md-2 col-sm-2 col-xs-2'>"+"<input type='hidden' value='"+info.pageNum+"' name='num' id='num'/>"+
	"共"+info.total+"条记录&nbsp;"+info.pageNum+"&nbsp;/&nbsp;"+info.pages+
	"</div>"+
	"<div class='col-md-offset-5 col-md-5 col-sm-offset-5 col-sm-5 col-xs-offset-5 col-xs-5'>"+
		"<nav aria-label='Page navigation'>"+
			"<ul class='pagination' style='margin: 0px'>";
				if(info.prePage>0){
					strPage = strPage+
					"<li><a href='#' onclick='backPages("+info.firstPage+")'"+
						">首页</a></li>"+
					"<li><a href='#' onclick='backPages("+info.prePage+")'"+
						">上一页</a></li>";
				}
				if(info.nextPage<=info.lastPage && info.nextPage>0){
					strPage = strPage+
					"<li><a href='#' onclick='backPages("+info.nextPage+")'>下一页</a></li>"+
					"<li><a href='#' onclick='backPages("+info.lastPage+")'>末页</a></li>";
				}
//			
			strPage = strPage+"</ul>"+
		"</nav>"+
	"</div>";
	//获取页面框对象
	var pageShow = $("#backPageShow");
	pageShow.html("");
	//console.info(strPage);
	pageShow.append(strPage);
	//pageShow.html(strPage);
	//var x = "<div class='col-md-2 col-sm-2 col-xs-2'>共11条记录&nbsp;2&nbsp;/&nbsp;3</div><div class='col-md-offset-5 col-md-5 col-sm-offset-5 col-sm-5 col-xs-offset-5 col-xs-5'><nav aria-label='Page navigation'><ul class='pagination' style='margin: 0px'><li><a href='#' onclick='backPages(1)'>首页</a></li><li><a href='#' onclick='backPages(1)'>上一页</a></li><li><a href='#' onclick='backPages(3)>下一页</a></li><li><a href='#' onclick='backPages(3)>末页</a></li></ul></nav></div>";
	//pageShow.html(x);
	//console.info(pageShow.html());
}





//审核
function backModal($appId){
	

//获取最新版本对象
var lookHtml = $("#backCheckNew tbody").html("");
//获取APP基础信息
var backBaseApp = $("#backCheckTable tbody").html("");
//获取查询条件
var id = $appId;
//获取路径
var url="getLookHtml";

//历史版本
var displayStr="";
var data="appId="+$appId+"&versionId=";

//查看页面
var lookStr="";
$.ajax({
	type:"POST",
	url:url,
	data:data,
	async:false,
	success:function(response){
		console.info(response);
		var list = response[0];
		var ver = response[1];
		for(var i=0;i<list.length;i++){
			lookStr="<tr style='border: 0px'>"+
			"<td class='rights'>软件名称*</td>"+
			"<td><input type='text' name='softwareName' class='form-control' value='"+list[i].softwareName+ "'readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>APK名称*</td>"+
			"<td><input type='text' name='APKName' class='form-control' value='"+list[i].apkname+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>支持ROM*</td>"+
			"<td><input type='text' name='supportROM' class='form-control' value='"+list[i].supportROM+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>界面语言*</td>"+
			"<td><input type='text' name='interfaceLanguage' class='form-control' value='"+list[i].interfaceLanguage
+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>软件大小*</td>"+
			"<td><input type='text' name='softwareSize' class='form-control' value='"+list[i].softwareSize+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>下载次数*</td>"+
			"<td><input type='text' name='downloads' class='form-control' value='"+list[i].downloads+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr style='border: 0px'>"+
			"<td class='rights'>所属平台*</td>"+
			"<td><input type='text' name='flatformName' class='form-control' value='"+list[i].flatformName+ "' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr>"+
			"<td class='rights'>所属分类*</td>"+
			"<td><input type='text' class='form-control' value='"+list[i].categoryLevel1Name
+ ">"+list[i].categoryLevel2Name+">"+list[i].categoryLevel3Name+"' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr>"+
			"<td class='rights'>APP状态*</td>"+
			"<td><input type='hidden' value='"+list[i].status+"' name='status'/>'"+
				"<input type='text' name='statusName' class='form-control' value='"+list[i].statusName+ "' readonly='readonly'/>"+
			"</td>"+
		"</tr>"+
		"<tr>"+
			"<td class='rights'>应用简介*</td>"+
			"<td><textarea datatype='*' nullmsg='请输入版本的相关信息,本信息作为该版本的详细信息进行版本介绍' name='appInfo' id='UIlanguage_txt' class='form-control' style='resize: none; width: 60%' ><s:property value="+list[0].appInfo+"/></textarea></td>"+
		"</tr>"+
		"<tr>"+
			"<td class='rights'>LOGO图片*</td>"+
			"<td><input type='text' name='logoPicPath' class='form-control' value='' readonly='readonly'/></td>"+
		"</tr>"+
		"<tr>" +
		"<td></td>" +
		"<td><button type='button' class='btn btn-default' onclick='throughCheck("+list[i].id+")' >审核通过</button>&nbsp;&nbsp;<button type='button' onclick='notParse("+list[i].id+",3)' class='btn btn-default'>审核不通过</button></td>"+
		"</tr>";
		
			backBaseApp.append(lookStr);
		}
		
		if(ver.length==0){
			return;
		}
//		for(var j=0;j<ver.length;j++){
			
			var tempAppName="";
			var tempApkFile="";
			if(null==ver[0].appInfo){
			
				ver[0].appInfo ="";
			
			
			if(ver[0].apkFileName==null){
			
				ver[0].apkFileName="";
			}
			}
			var tempTime=new Date(ver[0].creationDate);
			
			displayStr="<tr>"+
							"<td>"+ver[0].versionNo+
							"</td>"+
							"<td>"+ver[0].versionSize+"</td>"+
							"<td>"+ver[0].publishStatusName+"</td>"+
							"<td>"+ver[0].appInfo+"</td>"+
							"<td>"+ver[0].apkFileName+"</td>"+
						"</tr>";
			lookHtml.append(displayStr);
//		}
	},
	dataType:"JSON"
})


$("#backCheck").modal('toggle');

}


//审核APP通过
function throughCheck($id){
	//获取审核参数
	//var versionId = $versionId;
	var data = $id;
	//获取提交路径
	var url="backThrough";
	$.ajax({
		type:"POST",
		url:url,
		data:data,
	
		success:function(response){
			alert(response);
			//修改成功后
			
			if(response){
				alert("修改成功!");
			}else{
				alert("修改失败!");
			} 
			
			checkBackPage();
		}
	})
}

//APP审核不通过
function notParse($id){
	//获取审核参数
	var data = $id;
	//获取提交路径
	var url="backThroughw";
	$.ajax({
		type:"POST",
		url:url,
		data:data,
		async:false,
		success:function(response){
			if(response){
				//修改成功后
				if(response){
					alert("修改成功!");
				}else{
					alert("修改失败!");
				} 
			}
			checkBackPage();
		}
	})
}



//查询页面信息
function checkBackPage(){
	//获取提交表单信息，显示当前页
	var data = $("#backAppInfoForm").serialize();
	var page = $("#num").val();
	data = data+"&num="+page;
	//获取查询路径
	var url="getResponse";
	$.ajax({
		type:"POST",
		url:url,
		data:data,
		async:false,
		success:function(response){
			//响应的数据
			var result=response;
			showBackApp(result.list);
			backPageStr(response);
		},
		dataType:"JSON"
	})
}
